package com.codi.bus.core.dao.impl;

import com.codi.base.dao.BaseDAOImpl;
import com.codi.base.dao.PageImpl;
import com.codi.base.dao.plugin.page.PageView;
import com.codi.bus.core.dao.FundCombinationDao;
import com.codi.bus.core.domain.FundCombination;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("fundCombinationDao")
public class FundCombinationDaoImpl extends BaseDAOImpl<FundCombination> implements FundCombinationDao{

    @Override
    public List<FundCombination> queryFundCombinations() {
        List<FundCombination> combinations = this.findList(generateStatement("queryFundCombinations"));

        return combinations;
    }

    @Override
    public List<FundCombination> queryThreeFundCombinations() {
        List<FundCombination> combinations = this.findList(generateStatement("queryThreeFundCombinations"));

        return combinations;
    }

    @Override
    public FundCombination queryByCombinationCode(String combinationCode) {
        Map<String, Object> map = new HashMap<>();
        map.put("combinationCode", combinationCode);

        return this.getObject(generateStatement("queryByCombinationCode"), map);
    }

    @Override
    public List<FundCombination> queryPortfolio(List<String> portfolioCodes) {
        return this.findList("queryPortfolio", portfolioCodes);
    }

    @Override
    public List<FundCombination> queryAll() {
        return this.findList(generateStatement("queryAll"));
    }

    @Override
    public Page<FundCombination> query(Pageable pageable) {
        PageView pageView = getPageView(pageable.getPageNumber(), pageable.getPageSize());

        Map<String, Object> map = new HashMap<>();
        map.put("pageView", pageView);

        List<FundCombination> fundCombinations = this.findList(generateStatement("queryByPage"), map);

        return new PageImpl(fundCombinations, pageable, pageView.getRowCount());
    }

    @Override
    public int addPortfolio(FundCombination fundCombination) {
        return this.insert(generateStatement("insertSelective"), fundCombination);
    }

    @Override
    public int updatePortfolio(FundCombination fundCombination) {
        return this.update(generateStatement("updateByPrimaryKeySelective"), fundCombination);
    }

    @Override
    public int deleteByCombinationCode(String combinationCode) {
        return this.delete(generateStatement("deleteByCombinationCode"), combinationCode);
    }

    @Override
    public FundCombination queryByPrimaryKey(Long combinationId) {
        return this.getObject(generateStatement("selectByPrimaryKey"), combinationId);
    }

}
